﻿Imports System.Web.UI.WebControls

Namespace DotNetNuke.Modules.ActiveForums
    Partial Public Class profile_mypreferences
        Inherits SettingsBase
        Public Property UID() As Integer
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            nsPrefPageSize.Style.Add("float", "none")
            nsPrefPageSize.EmptyMessageStyle.CssClass += "dnnformHint"
            nsPrefPageSize.NumberFormat.DecimalDigits = 0
            nsPrefPageSize.IncrementSettings.Step = 5
            If Request.QueryString("UserId") Is Nothing Then
                UID = UserInfo.UserID
            Else
                UID = Convert.ToInt32(Request.QueryString("UserId"))
            End If
            'If UID <> UserInfo.UserID And Not UserInfo.IsInRole(PortalSettings.AdministratorRoleName) Then

            'End If
            Dim ui As UserProfileInfo = Nothing
            If ui Is Nothing And UID > 0 Then
                Dim up As New UserController
                ui = up.GetUser(PortalId, ForumModuleId, UID).Profile
            End If
            If Not ui Is Nothing Then
                With ui

                    drpPrefDefaultSort.SelectedIndex = drpPrefDefaultSort.Items.IndexOf(drpPrefDefaultSort.Items.FindByValue(.PrefDefaultSort.Trim))
                    nsPrefPageSize.Value = .PrefPageSize
                    chkPrefJumpToLastPost.Checked = .PrefJumpLastPost
                    chkPrefTopicSubscribe.Checked = .PrefTopicSubscribe
                    'chkPrefUseAjax.Checked = .PrefUseAjax
                    chkPrefBlockAvatars.Checked = .PrefBlockAvatars
                    chkPrefBlockSignatures.Checked = .PrefBlockSignatures
                    txtSignature.Text = .Signature
                End With
            End If
        End Sub
      
      
        Public Function GetString(key As String) As String
            Return Utilities.GetSharedResource(key)
        End Function

        Private Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
            If UserId = UID Or (CurrentUserType = CurrentUserTypes.Admin Or CurrentUserType = CurrentUserTypes.SuperUser) Then
                Dim upc As New UserProfileController
                Dim uc As New UserController
                Dim upi As UserProfileInfo = uc.GetUser(PortalId, ForumModuleId, UID).Profile
                If Not upi Is Nothing Then
                    With upi
                        .PrefDefaultSort = Utilities.XSSFilter(drpPrefDefaultSort.SelectedItem.Value, True)
                        .PrefPageSize = CInt(IIf(CInt(nsPrefPageSize.Text) < 5, 5, CInt(nsPrefPageSize.Text)))
                        .PrefDefaultShowReplies = False
                        .PrefJumpLastPost = chkPrefJumpToLastPost.Checked
                        .PrefTopicSubscribe = chkPrefTopicSubscribe.Checked
                        .PrefSubscriptionType = SubscriptionTypes.Instant
                        .PrefUseAjax = False
                        .PrefBlockAvatars = chkPrefBlockAvatars.Checked
                        .PrefBlockSignatures = chkPrefBlockSignatures.Checked
                        If MainSettings.AllowSignatures = 1 Or MainSettings.AllowSignatures = 0 Then
                            .Signature = Utilities.XSSFilter(txtSignature.Text, True)
                            .Signature = Utilities.StripHTMLTag(.Signature)
                            .Signature = Utilities.HTMLEncode(.Signature)
                        ElseIf MainSettings.AllowSignatures = 2 Then
                            .Signature = Utilities.XSSFilter(txtSignature.Text, False)
                        End If
                    End With
                    upc.Profiles_Save(upi)



                End If

            End If
        End Sub
    End Class
End Namespace